package com.sg.business.model.workevent;

import java.util.HashMap;
import java.util.Map;

import com.mobnut.db.model.IContext;
import com.mobnut.db.model.PrimaryObject;
import com.mobnut.db.model.TypedCustomizeEvent;
import com.sg.business.model.Work;
import com.sg.business.model.WorkEventNoticeRule;

public class RuleBasedWorkEvent extends TypedCustomizeEvent implements IWorkEvent {

	private WorkEventNoticeRule rule;
	private Map<String, Object> parameters;

	public RuleBasedWorkEvent(Work work, WorkEventNoticeRule rule , IContext context) {
		super(work, context);
		setRule(rule);
	}

	public RuleBasedWorkEvent(Work work, IContext context) {
		super(work, context);
	}
	
	public void setRule(WorkEventNoticeRule rule) {
		this.rule = rule;
		setEventTypeId(rule.getEventTypeId());
	}
	
	@Override
	public void setData(PrimaryObject data) {
		super.setData(data);
		setParameter("work", data);
	}
	
	
	public Work getWork(){
		return (Work) getData();
	}
	
	public WorkEventNoticeRule getRule() {
		return rule;
	}

	public Map<String,Object> getParameters() {
		return parameters;
	}
	
	public void setParameter(String key,Object value) {
		if (parameters == null) {
			parameters = new HashMap<String,Object>();
		}
		parameters.put(key, value);
	}

}
